package LinkedList.环形链表;

import LinkedList.ListNode;

public class Test {
    public boolean hasCycle(ListNode head) {

        ListNode slow = head;
        ListNode fast = head;

        int pos = 0;


        while(fast != null && fast.next != null && slow != null) {

            slow = slow.next;
            fast = fast.next.next;

            if(slow == fast) {
                while(head != slow) {
                    pos++;
                    head = head.next;
                }
                return true;
            }


        }

        return false;

    }
}
